Skip to content

Conversation

@m-a-king
Copy link
Collaborator

@m-a-king m-a-king commented Jan 8, 2025

resolved :

📌 과제 설명

OAuth 로그인 시, 리디렉션과 함께 응답을 제공하는 것은 문제가 있음을 확인했습니다.
정확히는 리디렉션과 데이터를 함께 전달하는 방식은 HTTP 표준에 어긋나고 불가합니다. 하지만 OAuth 로그인의 특성상 리디렉션은 필수적입니다.

이를 해결하기 위해:

  1. 소셜 로그인 완료 시, 백엔드가 쿠키에 로그인 토큰을 저장하고 /success으로 리디렉션합니다.
  2. 클라이언트(프론트엔드)는 /success으로 이동 시, 백엔드에 별도로 토큰 요청 API를 호출합니다.
  3. 백엔드는 클라이언트의 쿠키에서 로그인 토큰을 확인하고, 액세스 토큰을 별도의 응답 헤더에 담아 반환합니다.
  4. 프론트엔드는 반환된 헤더 정보를 활용해 액세스 토큰을 저장하거나 이후 요청에 사용할 수 있도록 처리합니다.

이 방법으로 리디렉션과 데이터 전달 문제를 해결하면서, 보안성을 유지할 수 있습니다.


👩‍💻 요구 사항과 구현 내용

  1. OAuth 로그인 후 리디렉션 처리

    • 리디렉션과 데이터 전달의 문제를 해결하기 위해, 로그인 완료 시 클라이언트는 /success 경로로 리디렉션됩니다.
    • 클라이언트는 /success 경로에 도달하면 토큰 요청을 위한 별도의 API를 호출합니다.
  2. 쿠키에 로그인 토큰 저장

    • OAuth 로그인 성공 시, 백엔드는 클라이언트의 브라우저에 로그인 토큰을 쿠키에 저장합니다.
  3. 토큰 요청 API 구현

    • 클라이언트는 /api/auth/token API를 호출하여 액세스 토큰을 요청합니다.
    • 백엔드는 쿠키에서 로그인 토큰을 읽고 생성해둔 액세스 토큰을 응답 헤더에 담아 반환합니다.

✅ PR 포인트 & 궁금한 점

  • 현재 로직이 추후 확장성 및 유지보수 측면에서 적합한 구조인지 의견 주시면 감사하겠습니다.

  • 토큰 타입 관련 리팩토링이 별거 없지만 최근 리팩토링 중에 가장 마음에 들어서 그런데 유심히 봐주세요~.

@m-a-king m-a-king self-assigned this Jan 8, 2025
@m-a-king m-a-king linked an issue Jan 8, 2025 that may be closed by this pull request
3 tasks
@Schema(description = "유저 ROLE")
String role
) {
public static UserInfoResponseDto from(UUID userId, UserRole role) {
Copy link
Collaborator

@7zrv 7zrv Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of라는 네이밍이 더 적절하다고 생각했는데 재중님 생각은 어떠신가요
저의 경우는
of : 데이터 필드값으로 객체를 생성할 때
from : 특정 객체로부터 객체가 생성될 때
로 인자값으로 객체가 들어올 때 from을 사용중이라 재중님 의견을 여쭤보고 싶습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아요 그 관점에서도 of가 더 적절한 것 같아요
제가 전부 from으로 시그니처를 만들어두고 구현해서 그렇습니다.. 수정할게요 감사합니다~~

ACCESS(1000 * 60 * 30),
REFRESH(1000 * 60 * 60 * 24 * 7),
SIGNOUT(0);
ACCESS(Duration.ofMinutes(30)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duration 기억하겠습니다... 좋네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 코드가 엄청 깔끔해져서 좋더라구요


private static ResponseCookie generateCookie(TokenType tokenType, String value) {
return ResponseCookie.from(TokenType.ACCESS.name(), value)
return ResponseCookie.from(TokenType.ACCESS.getDescription(), value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 from과 of 어떤게 적절할 지 의견나눠보면 좋을거 같아요!


return ApiResponse.ok(HttpStatus.OK.value(),
accessToken.getValueWithPrefix(),
"유저 정보 응답 성공");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두 메서드의 메세지가 같은데 어떤 의도가 있으신건지 궁금합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어 바로 수정했었습니다. 제가 놓쳤더라구요~~

import java.util.UUID;

@Service
@Slf4j
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드에 로깅 부분이 안보여서
이 부분도 제거해줘도 괜찮을 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 감사합니다

@7zrv
Copy link
Collaborator

7zrv commented Jan 8, 2025

현재 로직이 추후 확장성 및 유지보수 측면에서 적합한 구조인지 의견 주시면 감사하겠습니다.

전 클래스 구조적으로 책임도 잘 나뉘어있고 코드도 의도와 논리가 명확하게 보여서 좋았습니다
테스트도 잘 짜여졌다고 느꼈습니다
수정이 일어난다면 어떨까도 생각해봤는데 저는 유지보수하기에도 좋다는 생각입니다!

토큰 타입 관련 리팩토링이 별거 없지만 최근 리팩토링 중에 가장 마음에 들어서 그런데 유심히 봐주세요~.
깔끔한 리팩토링이라는 생각이 들었습니다 Duration 잘 사용하겠습니다

@m-a-king m-a-king force-pushed the feature/276-oauth-jwt-token branch from 7fcb3a0 to 6cfe14c Compare January 8, 2025 20:54
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 8, 2025

@m-a-king m-a-king merged commit 097e836 into main Jan 8, 2025
3 checks passed
@m-a-king m-a-king deleted the feature/276-oauth-jwt-token branch January 8, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] OAuth 로그인 토큰 문제 해결

3 participants